﻿// <copyright file="PersistenceNoKingIdException.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Contains the exception returned when no more King Id are available </summary>

namespace Sqwarea.Persistence.Exceptions
{
    using System;
    using System.Runtime.Serialization;
    using System.Security.Permissions;

    /// <summary>
    /// Persistence Exception : No new King Id available
    /// </summary>
    [Serializable]
    public class PersistenceNoKingIdException : PersistenceException
    {
        /// <summary>
        /// Initializes a new instance of the PersistenceNoKingIdException class
        /// </summary>
        /// <param name="kingId">Id of the not found king</param>
        /// <param name="message">Exception message</param>
        public PersistenceNoKingIdException(long kingId, string message)
            : base(message)
        {
            KingId = kingId;
        }

        /// <summary>
        /// Initializes a new instance of the PersistenceNoKingIdException class
        /// </summary>
        /// <param name="message">Exception message</param>
        public PersistenceNoKingIdException(string message)
            : base(message)
        {
        }

        /// <summary>
        /// Initializes a new instance of the PersistenceNoKingIdException class
        /// </summary>
        public PersistenceNoKingIdException()
        {
        }

        /// <summary>
        /// Initializes a new instance of the PersistenceNoKingIdException class
        /// </summary>
        /// <param name="message">Exception message</param>
        /// <param name="ex">Parent exception</param>
        public PersistenceNoKingIdException(string message, Exception ex)
            : base(message, ex)
        {
        }

        /// <summary>
        /// Initializes a new instance of the PersistenceNoKingIdException class
        /// </summary>
        /// <param name="info">Serialization infos</param>
        /// <param name="context">Streaming context</param>
        protected PersistenceNoKingIdException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        /// <summary>
        /// Gets the id of the not found king.
        /// </summary>
        public long KingId { get; private set; }

        /// <summary>
        /// Gets object data
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("KingId", KingId);
        }
    }
}